package exception;

/**
 * @author Administrator
 * @Description
 * 异常处理机制
 * @date 2022/5/5 11:55
 **/
public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("程序开始了");
        String str = null;
        str = "abc";
        try {

            System.out.println(str.length());
            System.out.println(str.charAt(0));
            //注意:try语句块中出错代码以下的内容均不会执行
            System.out.println("----------------------------");
        }
//        catch (NullPointerException e){
//            e.printStackTrace();
//        }catch (StringIndexOutOfBoundsException e){
//            e.printStackTrace();
//        }
        catch (NullPointerException | StringIndexOutOfBoundsException e){
            System.out.println("出现了空指针或字符串下标越界异常");
            e.printStackTrace();
        }
        System.out.println("程序结束了");
    }
}
